home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 September / Macworld (1998-09).dmg / Shareware World / Info / For Developers / MacZoop 1.8.3 / More Classes / Advanced Dialogs / ZAdvancedDialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-29  |  8.0 KB  |  243 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            ZAdvancedDialog.h    -- a dialog box that can be extended with new types of items.
  9. *                                    this will handle list boxes without subclassing.
  10. *
  11. *
  12. *            © 1997, Graham Cox
  13. *
  14. *
  15. *
  16. *************************************************************************************************/
  17.  
  18. #pragma once
  19.  
  20. #ifndef __ZADVANCEDDIALOG__
  21. #define    __ZADVANCEDDIALOG__
  22.  
  23.  
  24. #include    "ZDialog.h"
  25. #include    "ZObjectArray.h"
  26. #include    <Lists.h>
  27.  
  28. class    ZDialogItem;
  29.  
  30.  
  31. typedef    ZObjectArray<ZDialogItem>    ZDialogItemList;
  32.  
  33. typedef enum
  34. {
  35.     typeStaticText     = statText,
  36.     typeEditText     = editText,
  37.     typeIcon         = iconItem,
  38.     typePicture     = picItem,
  39.     typeButton         = btnCtrl,
  40.     typeCheckBox     = chkCtrl,
  41.     typeRadioButton = radCtrl,
  42.     typeResControl     = resCtrl,
  43.     typeUserItem    = 'user'
  44. }
  45. ItemType;
  46.  
  47.  
  48. // generic item class:
  49.  
  50. class    ZDialogItem : public ZCommander
  51. {
  52. protected:
  53.     short        id;                // dialog item ID
  54.     ItemType    type;            // item type
  55.     Handle        iHand;            // original item handle
  56.     Rect        bounds;            // bounding box
  57.     Boolean        enabled;        // TRUE if item enabled for clicks
  58.     Boolean        canBeHandler;    // TRUE if this item can become part of the cmd chain
  59.     Boolean        isHandler;        // TRUE if currently is the handler for typing, etc.
  60.  
  61. public:    
  62.     ZDialogItem( ZDialog* aDialog, short item );
  63.     virtual ~ZDialogItem() {};
  64.     
  65.     virtual void        DrawItem() { FrameRect( &bounds ); };
  66.     virtual void        ClickItem( const Point where, const short modifiers ) {};
  67.     virtual void        AdjustCursor( const Point where, const short modifiers );
  68.     virtual void        InitItem( const long param1, const long param2 ) {};
  69.     virtual void        DrawBorder( Boolean bState );
  70.     virtual void        Activate( const Boolean isActive ) {};
  71.     virtual void        Idle() {};
  72.     virtual void        Hilite( Boolean state ) {};
  73.     
  74.     virtual void        SetCanBeHandler( Boolean hState ) { canBeHandler = hState; };
  75.     virtual void        BecomeHandler( Boolean isBecoming );
  76.     virtual void        SetUpFontAndColours();
  77.     
  78.     inline    ItemType    GetType() { return type; };
  79.     inline    void        SetType( ItemType aType ) { type = aType; };
  80.     inline    Boolean        ContainsPoint( Point where ) { return PtInRect( where, &bounds ); };
  81.     inline    short        GetID() { return id; };
  82.     inline    Boolean        Enabled() { return enabled; };
  83.     inline    Boolean        CanBeHandler() { return canBeHandler; };
  84. };
  85.  
  86. // messages sent by items when they change focus
  87.  
  88. enum
  89. {
  90.     ItemNowHandler         = 'ich+',
  91.     ItemNoLongerHandler = 'ich-'
  92. };
  93.  
  94. // lists can be constructed from resource templates. Here is the definition for
  95. // the template:
  96.  
  97. #if PRAGMA_ALIGN_SUPPORTED
  98. #pragma options align=mac68k
  99. #endif
  100.  
  101. typedef struct
  102. {
  103.     short        rows;                // number of rows
  104.     short        columns;            // number of columns
  105.     short        stringsListID;        // ID number of STR# resource to fill list with
  106.     short        procID;                // LDEF proc ID (0 for standard)
  107.     Boolean        hasVertScroll : 1;    // TRUE if has vertical scrollbar
  108.     Boolean        hasHorizScroll : 1;    // TRUE if has horizontal scrollbar
  109.     Boolean        hasGrowBox : 1;        // TRUE if has grow box
  110.     Boolean        visible : 1;        // TRUE if initially visible
  111.     Boolean        keyboardNav : 1;    // TRUE if can have the keyboard focus
  112.     long        refCon;                // reference constant
  113.     short        fontSize;            // size of font to use (uses window font if 0).
  114.     Str63        fontName;            // which font to use.
  115. }
  116. ListTemplate, *ListTemplatePtr, **ListTemplateHdl;
  117.  
  118.  
  119. #define        kListTemplateResType    'LIST'
  120.  
  121.     
  122. #if PRAGMA_ALIGN_SUPPORTED
  123. #pragma options align=reset
  124. #endif
  125.  
  126. // subclass of item to handle list box item
  127.  
  128. class    ZListDialogItem : public ZDialogItem
  129. {
  130. protected:
  131.     ListHandle        theList;        // the list manager list
  132.     Cell            lastSel;        // cell selected when deactivated
  133.     Str15            searchStr;        // for finding items in a list
  134.     long            lastKeyTime;    // time last key was typed
  135.     short            fThresh;        // reset threshold for typing
  136.     short            font;            // which font
  137.     short            fontSize;        // what size font
  138.     short            strListID;        // ID of string list to use
  139.     short            listResID;        // ID of 'LIST' resource used
  140.  
  141. public:
  142.     ZListDialogItem( ZDialog* aDialog, const short item );
  143.     ~ZListDialogItem();
  144.  
  145.     virtual void        DrawItem();
  146.     virtual void        ClickItem( const Point where, const short modifiers );
  147.     virtual void        InitItem( const long param1, const long param2 );
  148.     virtual void        Type( const char theKey, const short modifiers );
  149.     virtual void        BecomeHandler( Boolean isBecoming );
  150.     virtual void        Activate( const Boolean isActive );
  151.     virtual void        SetUpFontForList( short* curFont, short* curSize );
  152.     virtual void        Hilite( Boolean state );
  153.  
  154. // managing list contents:    
  155.     virtual void        AppendString( Str255 aString, Boolean drawIt = TRUE );
  156.     virtual void        GetSelectedCell( Cell* startingCell );
  157.     virtual void        GetCellString( Cell aCell, Str255 aStr );
  158.     virtual void        SetCellString( Cell aCell, Str255 aStr );
  159.     virtual void        ResetAndClearList();
  160.     virtual void        SetCellData( Cell aCell, Ptr someBuf, short dataLen );
  161.     virtual void        GetCellData( Cell aCell, Ptr someBuf, short *dataLen );
  162.     virtual void        EnableDrawing();
  163.     virtual void        DisableDrawing();
  164.     virtual void        SelectCell( Cell aCell );
  165.  
  166.     inline    ListHandle    GetMacList() { return theList; };
  167.  
  168. protected:
  169.     virtual void        MakeMacList( const short listTemplateID = 0 );
  170.     virtual void        ActivateListItem( const Boolean state );
  171. };
  172.  
  173. // message sent from list box when a new item is selected
  174.  
  175. enum
  176. {
  177.     newListItemSelected = 'lstc',
  178.     listItemDoubleClicked = 'lsdb'
  179. };
  180.  
  181.  
  182. // advanced dialog class:
  183.  
  184. class    ZAdvancedDialog    : public ZDialog
  185. {
  186. protected:
  187.     ZDialogItemList*        itsItems;        // list of special object items
  188.     ZDialogItem*            curHandler;        // object that has keyboard focus
  189.     short                    focusItem;        // item ID that has focus, including real items
  190.  
  191. public:
  192.     ZAdvancedDialog( ZCommander* aBoss, const short dialogID );
  193.     ~ZAdvancedDialog();
  194.     
  195.     virtual    void            SetUp();
  196.     virtual void            ClickItem( const short item );
  197.     virtual void            DrawUserItem( const short item );
  198.     virtual Boolean            HasMultipleFoci();
  199.     virtual void            SelectItem( const short item );
  200.     virtual void            AdjustCursor( const Point mouse, const short modifiers );
  201.     virtual void            Deactivate();
  202.     virtual void            Activate();
  203.     virtual void            Type( const char theKey, const short modifiers );
  204.     virtual ZDialogItem*    GetObjectItem( const short item );
  205.     virtual ZCommander*        GetHandler();
  206.     virtual void            EnableItem( const short item );
  207.     virtual void            DisableItem( const short item );
  208.  
  209. protected:
  210.     virtual void            ParseStatTextPseudoObjects( Str255 sText,
  211.                                                         long* typeParam,
  212.                                                         long* param1,
  213.                                                         long* param2 );
  214.     virtual void            BuildItemList();
  215.     
  216.     virtual ZDialogItem*    MakeObjectItem( const long aType, const short id );
  217.     virtual ZDialogItem*    FindObjectItem( const Point where );
  218.     virtual void            HiliteDialogText( Boolean state );
  219.     virtual Boolean            SelectNextFocus( Boolean selectPrevious = FALSE );
  220.     virtual void            ReceiveMessage( ZComrade* aSender, long aMessage, void* msgData );
  221. };
  222.  
  223.  
  224. extern UserItemUPP    gUIVectorUPP;
  225.  
  226. // this dialog class can do everything an ordinary dialog can, but in addition can display list-manager
  227. // lists. By default, the lists are set up with strings obtained from a STR# resource. This functionality
  228. // is based on an embryonic general dialog enhancement technique that will be further developed once we
  229. // know what sort of things are needed. In the meantime, this will handle list manager list boxes without
  230. // further subclassing.
  231.  
  232. // How this works is through the use of pseudo-items in the DITL template. These are declared as static
  233. // text items, but containing a special string sequence that this object parses and converts to other
  234. // object-based items. The strings must start with two dollar signs followed by the name of the object
  235. // then followed by a comma-delimited parameter list. e.g. "$$LIST,128,0". When this object encounters
  236. // this, it will a) convert the item to a user item and set up a drawing procedure for it via an object
  237. // of type ZDialogItem, b) extract the parameters and pass them to the item's initialiser, c) handle
  238. // clicks, etc in the item.
  239.  
  240. // Though apparently complex, this is a very powerful and easy to use feature once you get the hang of
  241. // it, requiring nothing more than setting up your DITL and making this object with it.
  242.  
  243. #endif